package com.blockchain.front.servlets.financial;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.framework.http.servlet.annotation.PagingServlet;
import com.blockchain.framework.http.session.Session;
import com.blockchain.framework.http.session.authentication.AuthenticationException;
import com.blockchain.framework.http.session.authentication.VerifyCodeAuthentication;
import com.blockchain.framework.resource.PromptLevel;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.front.service.financial.FinancialManage;
import com.blockchain.util.parser.BigDecimalParser;
import com.blockchain.util.parser.IntegerParser;
@PagingServlet(itemServlet = XlbZc.class)
public class XlbZc extends AbstractFinancialServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		processPost(request, response, serviceSession);
	}

	@Override
	protected void processPost(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int bid=IntegerParser.parse(request.getParameter("bid"));
		String url=getController().getViewURI(request,XlbZc.class)+"?bid="+bid;
		BigDecimal sl=BigDecimalParser.parse(request.getParameter("sl"));
		String jymm=request.getParameter("jymm");
		int qbid=IntegerParser.parse(request.getParameter("qbid"));
		VerifyCodeAuthentication authentication = new VerifyCodeAuthentication();
		String zcxlbverifyCode = request.getParameter("zcxlbverifyCode");
		authentication.setVerifyCodeType("XLBZC"+request.getParameter("phone"));
		authentication.setVerifyCode(zcxlbverifyCode);
		Session session = serviceSession.getSession();
		try {
			session.authenticateVerifyCode(authentication);
		} catch (AuthenticationException e) {
			prompt(request, response, PromptLevel.ERROR, e.getMessage());
			sendRedirect(request, response,url);
			return;
		}
		FinancialManage manage=serviceSession.getService(FinancialManage.class);
		manage.addXlbZc(bid, sl, jymm, qbid);
		prompt(request, response, PromptLevel.INFO, "申请成功，我们将尽快为您处理！");
		sendRedirect(request, response,url);
	}
}
